package com.yiwenup.leetcode.top_interview_150;

import java.util.Arrays;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-21 14:48:21
 * @Description https://leetcode.cn/problems/longest-consecutive-sequence/?envType=study-plan-v2&envId=top-interview-150
 */
public class No0128 {
    public int longestConsecutive(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int ans = 0;
        int curCount = 1;
        Arrays.sort(nums);
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) {
                continue;
            }
            if (nums[i] != nums[i - 1] + 1) {
                ans = Math.max(ans, curCount);
                curCount = 1;
            } else {
                curCount += 1;
            }
        }
        ans = Math.max(ans, curCount);
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new No0128().longestConsecutive(new int[]{0, 3, 7, 2, 5, 8, 4, 6, 0, 1}));
    }
}
